Skip to content

gh-160162: Fix crash in int left shift with huge count on 32-bit - #160163

Merged
gpshead merged 1 commit into
python:mainfrom
gpshead:int-lshift-32bit-overflow
Oct 22, 2026
Merged

gpshead merged 1 commit into
python:mainfrom
gpshead:int-lshift-32bit-overflow

Conversation

@gpshead

@gpshead gpshead commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Tighten the existing 32-bit-only bound on the shift count in long_lshift_int64() from PY_SSIZE_T_MAX * PyLong_SHIFT to MAX_LONG_DIGITS * PyLong_SHIFT. Any word shift above MAX_LONG_DIGITS could never be allocated anyway, and with it bounded oldsize + wordshift + 1 cannot overflow Py_ssize_t, so long_lshift1() stays unchanged and 64-bit builds are unaffected (the check is compiled out there).

The crash only reproduces on 32-bit builds; on 64-bit the new test passes before and after the fix because those counts already overflow int64_t.

ANT-2026-9YXRBW87

Bound the shift count by MAX_LONG_DIGITS*PyLong_SHIFT instead of
PY_SSIZE_T_MAX*PyLong_SHIFT, so that the result size computed in
long_lshift1() cannot overflow Py_ssize_t.
@gpshead gpshead added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 22, 2026
@gpshead gpshead self-assigned this Oct 22, 2026
@gpshead gpshead added the sprint label Oct 22, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Sprint Oct 22, 2026
@gpshead
gpshead marked this pull request as ready for review October 22, 2026 03:49
@gpshead
gpshead merged commit d4750a7 into python:main Oct 22, 2026
64 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@github-project-automation github-project-automation Bot moved this from Todo to Done in Sprint Oct 22, 2026
@bedevere-app

bedevere-app Bot commented Oct 22, 2026

Copy link
Copy Markdown

GH-160169 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 22, 2026
@bedevere-app

bedevere-app Bot commented Oct 22, 2026

Copy link
Copy Markdown

GH-160170 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 22, 2026
gpshead added a commit that referenced this pull request Oct 22, 2026
…it (GH-160163) (#160170)

gh-160162: Fix crash in int left shift with huge count on 32-bit (GH-160163)

Bound the shift count by MAX_LONG_DIGITS*PyLong_SHIFT instead of
PY_SSIZE_T_MAX*PyLong_SHIFT, so that the result size computed in
long_lshift1() cannot overflow Py_ssize_t.
(cherry picked from commit d4750a7)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
gpshead added a commit that referenced this pull request Oct 22, 2026
…it (GH-160163) (#160169)

gh-160162: Fix crash in int left shift with huge count on 32-bit (GH-160163)

Bound the shift count by MAX_LONG_DIGITS*PyLong_SHIFT instead of
PY_SSIZE_T_MAX*PyLong_SHIFT, so that the result size computed in
long_lshift1() cannot overflow Py_ssize_t.
(cherry picked from commit d4750a7)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant